package com.work.formaldehyde.activityadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.work.formaldehyde.R;
import com.work.formaldehyde.util.ApiUtils;

import java.util.ArrayList;

public class JianCeJiLusAdapter extends BaseAdapter {
    ArrayList<String> list;
    ArrayList<String> lists;
    Context context;
    private  int sid=0;

    public JianCeJiLusAdapter(ArrayList<String> list,ArrayList<String> lists, Context context) {
        // TODO Auto-generated constructor stub
        this.list = list;
        this.lists = lists;
        this.context = context;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list != null ? list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list != null ? list.get(position) : 0;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ApiUtils.SetLog(position+"");
        convertView = LayoutInflater.from(context).inflate(R.layout.item_jiance_zhuwo, null);
        init i = new init();
        i.msg_jiance_item_title = convertView.findViewById(R.id.msg_jiance_item_title);
        i.woshi_item_check_img = convertView.findViewById(R.id.woshi_item_check_img);
        if (lists.get(position).equals("1")) {
            i.woshi_item_check_img.setVisibility(View.GONE);
        }
        if(position>0){
            sid++;
            if(list.get(sid).equals(list.get(position--))){
                i.msg_jiance_item_title.setVisibility(View.GONE);
            }else{
                i.msg_jiance_item_title.setText(list.get(position).substring(0,4));
            }
        }else{
            i.msg_jiance_item_title.setText(list.get(position).substring(0,4));
        }
//        if(position>0)
//            for (int sid=0;sid<list.size();sid++){
//                if(sid>0&&list.get(sid).equals(list.get(sid--))){
//                    i.msg_jiance_item_title.setVisibility(View.GONE);
//                }else{
//                    i.msg_jiance_item_title.setText(list.get(position).substring(0,4));
//                    ApiUtils.SetLog("2");
//                }
//            }
//        else{

//        }
        convertView.setTag(i);
        return convertView;
    }

    public static class init {
        //首页list的子控件
        ImageView woshi_item_check_img;
        TextView msg_jiance_item_title;
    }
}

